17. Exercise: Adding More Features
Exercise: Adding More Features
In this exercise you will get to add a few more features to our app based on the feedback we collected from users.
- Change the water-all click event in the widget to water only that specific plant shown which involves
- Add the plantId as a new parameter to the updatePlantWidgets method
- Change the watering service action from ACTION_WATER_PLANTS to ACTION_WATER_PLANT
- Change the update query to use a SINGLE_PLANT_URI
- Define and using EXTRA_PLANT_ID to pass the plant ID to the intent service from the widget
- Call putExtra and passing the plantId when creating the pending intent for the watering service
- Call getLongExtra to extract the plnatId in the service
- Make sure you update the widgets after watering by calling startActionUpdatePlantWidgets
- Hide the water drop button in the widget if it’s been less than MIN_AGE_BETWEEN_WATER since it was last watered
- Add a new boolean parameter to updatePlantWidgets to indicate if the plant can be watered or not
- Use setViewVisibility to change the widget_water_button Visibility from View.VISIBLE to View.INVISIBLE to hide it
- Change the widget plant image click handler to launch the Detail Activity for that plant rather than the Main Activity
- If plantId was INVALID_PLANT_ID, then launch the MainActivity as usual
- Otherwise launch the PlantDetailActivity passing in the plantId as EXTRA_PLANT_ID
- Add a TextView underneath the plant image that displays the plant ID in both the main activity as well as in the widget to help identify each plant
Exercise Code
Exercise: TWID.04-Exercise-Extras
Task Description:
Now it's your turn, follow the following steps to complete this exercise